<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 武露斌
  Date: 2021/10/27
  Time: 11:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="../../js/jquery-1.8.2.min.js"></script>
    <script src="../../js/fileupload.js"></script>
    <script src="../../css/img.css"></script>
    <link rel="stylesheet" href="../../bootstrap-4.6.0-dist/css/bootstrap.min.css">
</head>
<body>
<form action="list.do" method="post">
    <input type="hidden" name="pageNum"><br>
    小区名称：<input type="text" name="hname" value="${map.hname}">
    出租状态：
    <select name="statu">
        <option value="">请选择出租状态</option>
        <option value="0" ${map.statu==0?"selected":""}>待租</option>
        <option value="1" ${map.statu==1?"selected":""}>已租</option>
    </select>

    <input type="submit" value="查询"  class="btn btn-info">
    <input type="button" value="刷新"  class="btn btn-primary" onclick="sx()">
</form>

<table class="table table-hover">
    <tr>
       <th>编号</th>
       <th>小区名称</th>
       <th>单元楼</th>
       <th>门牌号</th>
       <th>实景图</th>
       <th>状态</th>
       <th>挂牌时间</th>
       <th>出租时间</th>
       <th>户型</th>
       <th>操作</th>
    </tr>
    <c:forEach items="${pageInfo.list}" var="a">
        <tr>
            <td>${a.hid}</td>
            <td>${a.hname}</td>
            <td>${a.building}</td>
            <td>${a.number}</td>
<%--            <td>${a.img}</td>--%>
            <td>
                <img src="${a.imgs}" width="60">
            </td>
<%--            <td>${a.statu}</td>--%>
            <td>
                <c:if test="${a.statu==0}">
                    待租
                </c:if>
                <c:if test="${a.statu==1}">
                    已租
                </c:if>
            </td>
            <td>${a.gtime}</td>
            <td>${a.ctime}</td>
            <td>${a.tname}</td>
            <td>

                <c:if test="${a.statu==0}">
                    <input type="button" class="btn btn-success" value="出租" onclick="updacz(${a.hid})">
                    <input type="button" class="btn btn-danger" value="删除" onclick="del(${a.hid})">
                    <input type="button" class="btn btn-secondary" value="修改" onclick="upda(${a.hid})">
                </c:if>
                <c:if test="${a.statu==1}">
                    <input type="button"  class="btn btn-warning" value="退租" onclick="updatz(${a.hid})">
                </c:if>
            </td>
        </tr>
    </c:forEach>

    <tr>
        <td colspan="20" >
            <nav aria-label="Page navigation example">
                <ul class="pagination  justify-content-center">
                    <li class="page-item">
                        <input type="button" class="page-link" value="添加" onclick="add()">
                    </li>

                    <li class="page-item"><a class="page-link">${pageInfo.pageNum}/${pageInfo.pages}</a></li>
                    <li class="page-item"><a class="page-link" onclick="fy(1)">首页</a></li>
                    <li class="page-item"><a class="page-link" onclick="fy(${pageInfo.isFirstPage?1:pageInfo.prePage})">上一页</a></li>

                    <c:forEach items="${pageInfo.navigatepageNums}" var="index">
                        <li class="page-item ${pageInfo.pageNum==index?'active':''}">
                            <a class="page-link" onclick="fy(${index})">${index}</a>
                        </li>
                    </c:forEach>

                    <li class="page-item"><a class="page-link" onclick="fy(${pageInfo.isLastPage?pageInfo.pages:pageInfo.nextPage})">下一页</a></li>
                    <li class="page-item"><a class="page-link" onclick="fy(${pageInfo.pages})">尾页</a></li>
                </ul>
            </nav>
        </td>
    </tr>
</table>

</body>
</html>
<script>

    function fy(pageNum) {
        $("[name='pageNum']").val(pageNum)
        $("form").submit();
    }

    function sx() {
        location="list.do"
    }

    function del(hid) {
        if(confirm("确定要删除ID为"+hid+"的户型吗？")){
            $.ajax({
                url:"del.do",
                data:{"hid":hid},
                type:"post",
                dataType:"json",
                success:function (data) {
                    if (data>0){
                        alert("删除成功")
                        location="list.do"
                    }else{
                        alert("删除失败")
                    }
                }
            })
        }else{
            alert("看后悔了吧")
        }
    }

    function updacz(hid) {
        $.ajax({
            url: "updacz.do",
            data: {"hid":hid},
            type: "post",
            dataType: "json",
            success:function (data) {
                if (data>0){
                    alert("出租成功！！！")
                    location="list.do"
                }else{
                    alert("出租失败")
                }
            }
        })
    }
    function updatz(hid) {
        $.ajax({
            url: "updatz.do",
            data: {"hid":hid},
            type: "post",
            dataType: "json",
            success:function (data) {
                if (data>0){
                    alert("退租成功！！！")
                    location="list.do"
                }else{
                    alert("退租失败")
                }
            }
        })
    }

    function add() {
        location="addto.do"
    }

    function upda(hid) {
        location="updato.do?hid="+hid;
    }

</script>
























